package gson.Test;

import com.google.gson.JsonObject;

public class Messages extends BaseMessage {

    public static final String RESULT = "result";

    public static final String ORDER = "order";

    public static final String MSG = "message";

    private boolean mResult;

    private int mOrder;

    private String mMsg;

    public void setResult(boolean res) {
        mResult = res;
    }

    public void setOrder(int order) {
        mOrder = order;
    }

    public void setMsg(String msg) {
        mMsg = msg;
    }

    public boolean getResult() {
        return mResult;
    }

    public int getOrder() {
        return mOrder;
    }

    public String getMsg() {
        return mMsg;
    }



    public static String packToJson(Messages msg) {
        JsonObject jobj = new JsonObject();				//打包成String并发送
        jobj.addProperty(RESULT, msg.mResult);
        jobj.addProperty(ORDER, msg.mOrder);
        jobj.addProperty(MSG, msg.mMsg);
        return  jobj.toString();
    }

    public static Messages parseJson(String jstr) {
        Messages message = new Messages();
        JsonObject jobj = mParser.parse(jstr).getAsJsonObject();
        message.mResult = jobj.get(RESULT).getAsBoolean(); //消息是否传递成功
        message.mOrder = jobj.get(ORDER).getAsInt();
        message.mMsg = jobj.get(MSG).getAsString();        //消息，包含list和type  格式为String类型
        return message;
    }
}

